<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        var arr = [1, '1', true];
        //Array.push(添加的数组元素,添加的数组元素)有返回值,返回值是新数组的长度及arr.length,在数组后面添加
        var newArr = arr.push(1, '2');
        //这里先输出的arr数组,在输出的arr.push(1,'2')
        console.log(arr); //[1,'1',1,'2',1,'2']
        console.log(arr.push(1, '2')); //arr.push(1,'2')输出的结果为arr.length 7

        var arr = [1, '1'];
        //Array.unshift(添加的数组元素,添加的数组元素)在数组前面添加;
        var newArr = arr.unshift(1, '2');
        console.log(arr); //[1, "2", 1, "1"]
        console.log(arr.unshift(1, '2')); //6

        var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
        var num = arr.pop();
        console.log(arr); //[1, 2, 3, 4, 5, 6, 7, 8]
        console.log(num); //9 返回被删除的值


        var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
        var num = arr.shift();
        console.log(arr); //[2, 3, 4, 5, 6, 7, 8,9]
        console.log(num); //1 返回被删除的值


        //数组的排序
        var arr = ['abc', , false, , 'b', 'abcd', 1, 123, 22, true, null, undefined, 'ab'];
        arr.sort();
        //默认sort是将数组由Number(首数字优先级高(1-9)例如[2,22,1,16,5].sort===[1,16,2,22,5])到String(首字母优先级较高a到z,第二级优先级为数组长度)到false到null到true到undefined到empty
        console.log(arr);
        var arr = [1, 12, 22, 23, 1325, 22, 35];
        var newArr = arr.sort(
            function (a, b) {
                return a - b; //升序冒泡
            }
        )
        console.log(newArr);
        console.log(arr);
        var arr = [1, 12, 22, 23, 1325, 22, 35];
        arr.sort(
            function (a, b) {
                return b - a; //降序冒泡
            }
        )
        console.log(arr);

        //Array.indexOf() 当在数组内找到该元素后,返回从左到右该元素的索引号,没有找到时返回-1
        console.log(arr.indexOf(22)); //


        //Array.lastIndexOf() 当在数组内找到该元素后,返回从右到左该元素的索引号,没有找到时返回-1
        console.log(arr.lastIndexOf(22))

        //以上方法均会改变原先的数组
    </script>
</head>

<body>

</body>

</html>